/**
 * <p>Title: ServiceZMCM24.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 张志芳
 * @version 1.0
 * <pre>Histroy:
 *          2011-9-16 下午05:00:50  张志芳  Create
 *</pre>
 */
package com.baosight.sczx.zm.cm.service;

import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.threadlocal.UserSession;
import com.baosight.iplat4j.ep.ServiceEPBase;
import com.baosight.sczx.common.zm.basetools.StaticTools;
import com.baosight.sczx.common.zm.cInterface.Department;
import com.baosight.sczx.common.zm.cInterface.User;
import com.baosight.sczx.common.zm.cInterface.cm.MaterialType;
import com.baosight.sczx.common.zm.cInterface.cs.Engineering;
import com.baosight.sczx.common.zm.cInterface.cs.InitialData;
import com.baosight.sczx.common.zm.cInterface.cs.SystemSettingCM;
import com.baosight.sczx.zm.cm.domain.ZMCMTeammaterialplan;

/**
 * 区队年需求计划审批
 * <p>Title: ServiceZMCM24.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 张志芳
 * @version 1.0
 * <pre>Histroy:
 *          2011-9-16 下午05:00:50  张志芳  Create
 *</pre>
 */
public class ServiceZMCM24 extends ServiceEPBase {
	
	/**
	 * 初始化
	 * <p>Function: initLoad</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCM27</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-9-16下午05:03:22 张志芳
	 * </p>
	 *
	 */
	@Override
	public EiInfo initLoad(EiInfo inInfo) {
		inInfo.addBlock(EiConstant.resultBlock).set("showCount", "true");//如果不加这个，翻页的统计和显示是错误的
		EiInfo outInfo = this.query(inInfo);
		outInfo.addBlock(InitialData.getInstance().getEiBlockByNo("cmes.cs.units"));
		outInfo.addBlock(InitialData.getInstance().getEiBlockByNo("cmes.cm.financeClassify"));
		outInfo.addBlock(User.getInstance().getConstructionStaff("cmes.cm.empName", "empCode", "empName", false));
		outInfo.addBlock(Department.getInstance().getConstructionUnit("cmes.cm.department", "orgCode", "orgName", false));
		outInfo.set("orgCode",UserSession.getInSessionProperty("orgCode"));//当前用户所属单位ID
		outInfo.set("orgName",UserSession.getInSessionProperty("orgName"));//当前用户所属单位
		outInfo.set("UserCname", UserSession.getInSessionProperty("UserCname"));//当前登录用户名
		outInfo.set("userId", UserSession.getUserId());//当前登录用户ID
		outInfo.set("fdAuditDepartmentId",SystemSettingCM.getInstance().getDepartmentId());//审核单位ID
		outInfo.addBlock(MaterialType.getMateroalName());

		return outInfo;
	}
	
	/**
	 * 查询
	 * <p>Function: query</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCM27</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-9-16下午05:03:09 张志芳
	 * </p>
	 *
	 */	
	@Override
	public EiInfo query(EiInfo inInfo) {
		String fdParentId = inInfo.getString("fdParentId");//树节点ID
		StaticTools.setQueryParameters(inInfo,"fdYear",fdParentId,true);//添加查询条件		
		StaticTools.setQueryParameters(inInfo,"fdApprovePeople",UserSession.getUserId().toString(),true);//审批人
		StaticTools.setQueryParameters(inInfo,"notNeedApprove","审批模块",true);//添加查询条件
		
		EiInfo outInfo = super.query(inInfo, "ZMCMTeammaterialplan.query",new ZMCMTeammaterialplan());
		outInfo.addBlock(Engineering.getApplyProject("cmes.cm.applyProject", true));
		return outInfo;
	}
	
	/**
	 * 审批
	 * <p>Function: approve</p>
	 * <p>Description: </p>
	 * <p>return value:EiInfo</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-6-13 下午06:30:43  贾雪民
	 * </p>
	 *
	 */
	public EiInfo approve(EiInfo inInfo) 
	{
		inInfo.getBlock(EiConstant.resultBlock).setCell(0, "fdHistory", 
						UserSession.getInSessionProperty("UserCname")+"审批；");
		EiInfo _temp = super.update(inInfo, "ZMCMTeammaterialplan.approve");
		EiInfo  outInfo = this.query(inInfo);
		outInfo.setMsg(_temp.getMsg());
		outInfo.setDetailMsg(_temp.getDetailMsg());
		return outInfo;
	}
	
	/**
	 * 撤回
	 * <p>Function: qxreturn</p>
	 * <p>Description: </p>
	 * <p>return value:EiInfo</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2012-6-25 下午14:30:43  王堃
	 * </p>
	 *
	 */
	public EiInfo qxreturn(EiInfo inInfo) {
		  EiInfo _temp = super.update(inInfo, "ZMCMTeammaterialplan.qxreturn");
		  EiInfo  outInfo = this.query(inInfo);
	      outInfo.setMsg(_temp.getMsg());
	      outInfo.setDetailMsg(_temp.getDetailMsg());
	      return outInfo;
	}
}
